home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / mui / bcc_src.lha / Parser / ParseFile.cpp < prev    next >
C/C++ Source or Header  |  1998-03-15  |  3KB  |  137 lines

  1. #include "ParseFile.h"
  2. #include "ValidFile.h"
  3. #include "Global.h"
  4.  
  5. #include <string.h>
  6.  
  7. short ParseFile::Open( char *name, short force, short scanonly )
  8. {
  9.     created = 0;
  10.  
  11.     if( !Load( name ) ) return 0;
  12.  
  13.     Name = name;
  14.     sfname = name;
  15.     ofname = name;
  16.     
  17.     short p;
  18.     p = sfname.Pos( ".b", -1 );
  19.     if( p < 0 ) {
  20.         printf( "File %s has bad extension\n", name );
  21.         return 0;
  22.     }
  23.  
  24.     sfname.Cut( p, sfname.Len-p );
  25.     ofname.Cut( p+1 );
  26.     
  27.     ValidFile vf;
  28.     if( !Prefs.forcetrans && ((!force && vf.isValid( name, ofname )) || scanonly) ) {
  29.         strcpy( ofname, "NIL:" );
  30.         if( Prefs.verbose ) printf( "Scanning \"%s\"\n", name );
  31.     } else {
  32.         if( Prefs.verbose ) printf( "Translating \"%s\" into \"%s\"\n", name, (char*)ofname );
  33.         created = 1;
  34.     }
  35.  
  36.     if( !(ofh = fopen( ofname, "w" )) ) {
  37.         printf( "Can not open output file\n" );
  38.          Close();
  39.         return 0;
  40.     }
  41.             
  42.     copy = 1; startcopy = 0;
  43.  
  44.     return 1;
  45.  
  46. }
  47.  
  48. void ParseFile::Close( void )
  49. {
  50.  
  51.     if( ofh ) {
  52.         fclose( ofh );
  53.         ofh = 0;
  54.     }
  55.  
  56. }
  57.  
  58. ParseFile::~ParseFile()
  59. {
  60.     Close();
  61. }
  62.  
  63. ParseFile::ParseFile( void )
  64. {
  65.     ofh = 0;
  66. }
  67.  
  68.  
  69. void ParseFile::GetToken( void )
  70. {
  71.  
  72.     if( TokLen ) {
  73.         memcpy( PrevTok, Tok, TokLen );
  74.         PrevTok[TokLen] = 0;
  75.         PrevType = TokType;
  76.     } else PrevTok[0] = 0;
  77.  
  78.     if( copy && !Survey.Tok && TokLen ) {
  79.         if( fwrite( Tok, 1, TokLen, ofh ) != TokLen ) {
  80.             printf( "IO Error\n" );
  81.         }
  82.     }
  83.  
  84.     if( startcopy ) { copy = 1; startcopy = 0; }
  85.  
  86.     char *lch = Tok+TokLen;
  87.  
  88.     Next();
  89.  
  90.     if( copy && !Survey.Tok && lch && Tok-lch ) {
  91.         if( fwrite( lch, 1, Tok-lch, ofh ) != Tok-lch ) {
  92.             printf( "IO Error\n" );
  93.         }
  94.     }
  95.  
  96. }
  97.  
  98. static char *ErrTab[] = {
  99.     "Unknown error",
  100.     "Class name must be the same as file name",
  101.     "\"{\" must follow",
  102.     "Missing \";\"",
  103.     "Alfa-numerical string expected",
  104.     "\"(\" must follow",
  105.     "Non defined class",
  106.     "Missing \"::\"",
  107.     "Not a member of class",
  108.     "[S][G][I] must follow \":\"",
  109.     "Attribute must be 'S', 'G', 'I' or 'SI'",
  110.     "Non defined attribute",
  111.     "Unexpected end of file",
  112.     "Bad method parameter",
  113.     "Simple attributes don't need declaration",
  114.     "Current BCC version can handle only Class pointers",
  115.     "Bad class pointer definition",
  116.     "Can not declare code for virtual object",
  117.     "Missing Class type",
  118.     "Pointer doesn't point to class",
  119.     "Options syntax error",
  120.     "Parameter must be all in one line",
  121.     "Constructor must be AFTER all init attributes",
  122.     "Attribute can't be SET/INIT and GET at the same time",
  123.     "Too many nested BCCBlocks",
  124.     "Not closed BCCBlock",
  125.     "When custom OM_SET/OM_GET defined use ONLY virtual attributes",
  126.     "Empty brackets not allowded for Attributes"
  127. };
  128.  
  129. char **ParseFile::ErrorStrings( void ) { return ErrTab; }
  130.  
  131.  
  132. void ParseFile::UpdateLineNo( void )
  133. {
  134.  
  135.     if( Prefs.reallines ) fprintf( ofh, "#line %hd \"%s\"\n", LineN - ( *(Tok+TokLen-1)==10 ? 1 : 0 ) , (char*)Name );
  136.  
  137. }